//根据id获取部门或者人员信息或者角色信息
import cache from "@/utils/cache";
import tool from "@/utils/tool";

let data={};

//根据id获取部门或者人员信息或者角色信息
export const getNameById = (id) => {
	data[id] = null;
	if (!data[id]) {
		getUserNameById(id);
	}
	if (!data[id]) {
		getRoleNameById(id);
	}
	if (!data[id]) {
		getDeptNameById(id);
	}
	return data[id] || "未知";
}
export const getDeptNameById = (id) => {
	data[id] = null;
	getName("SysOrganization",id);
	return data[id];
}

export const getRoleNameById = (id) => {
	data[id] = null;
	getName("SysRole",id);
	return data[id];
}

export const getUserNameById = (id) => {
	data[id] = null;
	getName("SysUser",id);
	return data[id];
}

export const getName=async (code, id) => {
	data[id] = await cache.dic.label(code, id, true);
}

export const sleep = (time) => {
	let timeStamp = new Date().getTime();
	let endTime = timeStamp + time;
	while (true) {
		if (new Date().getTime() > endTime) {
			return;
		}
	}
}
